{"ast":null,"code":"import _regeneratorRuntime from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js\";import _asyncToGenerator from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from'react';import{Modal,Upload}from'antd';import'./UploadFiles.scss';import{jsx as _jsx}from\"react/jsx-runtime\";import{Fragment as _Fragment}from\"react/jsx-runtime\";import{jsxs as _jsxs}from\"react/jsx-runtime\";var getBase64=function getBase64(file){return new Promise(function(resolve,reject){var reader=new FileReader();reader.readAsDataURL(file);reader.onload=function(){return resolve(reader.result);};reader.onerror=function(error){return reject(error);};});};var UploadFiles=function UploadFiles(_ref){var uploaded=_ref.uploaded,callbackOnDeleteContent=_ref.callbackOnDeleteContent;var _React$useState=React.useState(false),_React$useState2=_slicedToArray(_React$useState,2),previewOpen=_React$useState2[0],setPreviewOpen=_React$useState2[1];var _React$useState3=React.useState(''),_React$useState4=_slicedToArray(_React$useState3,2),previewImage=_React$useState4[0],setPreviewImage=_React$useState4[1];var _React$useState5=React.useState(''),_React$useState6=_slicedToArray(_React$useState5,2),previewTitle=_React$useState6[0],setPreviewTitle=_React$useState6[1];var _React$useState7=React.useState([{}]),_React$useState8=_slicedToArray(_React$useState7,2),fileList=_React$useState8[0],setFileList=_React$useState8[1];React.useEffect(function(){var _uploaded$items;var tempFileList=[{}];setFileList(tempFileList);if(((_uploaded$items=uploaded.items)===null||_uploaded$items===void 0?void 0:_uploaded$items.length)>0){uploaded.items.forEach(function(item,index){if(item.id){tempFileList[index]={uid:item.id.toString(),status:\"done\",url:process.env.REACT_APP_BACKEND_URL+'/'+item.link,name:(process.env.REACT_APP_BACKEND_URL+'/'+item.link).split('/')[7]};}});setFileList(tempFileList);}},[uploaded]);var handleCancel=function handleCancel(){return setPreviewOpen(false);};var handlePreview=/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(file){return _regeneratorRuntime().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(!(!file.url&&!file.preview)){_context.next=4;break;}_context.next=3;return getBase64(file.originFileObj);case 3:file.preview=_context.sent;case 4:setPreviewImage(file.url||file.preview);setPreviewOpen(true);setPreviewTitle(file.name||file.url.substring(file.url.lastIndexOf('/')+1));case 7:case\"end\":return _context.stop();}}},_callee);}));return function handlePreview(_x){return _ref2.apply(this,arguments);};}();/*const handleChange: UploadProps['onChange'] = ({ fileList: newFileList}) => {\n        setFileList(newFileList);\n    }*/return/*#__PURE__*/_jsx(_Fragment,{children:fileList&&/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(Upload,{action:\"https://www.mocky.io/v2/5cc8019d300000980a055e76\",listType:\"picture-card\",fileList:fileList,onPreview:handlePreview,onRemove:function onRemove(data){return callbackOnDeleteContent(data.uid);}}),/*#__PURE__*/_jsx(Modal,{open:previewOpen,title:previewTitle,footer:null,onCancel:handleCancel,children:/*#__PURE__*/_jsx(\"img\",{alt:\"example\",style:{width:'100%'},src:previewImage})})]})});};export default UploadFiles;","map":{"version":3,"names":["React","Modal","Upload","getBase64","file","Promise","resolve","reject","reader","FileReader","readAsDataURL","onload","result","onerror","error","UploadFiles","uploaded","callbackOnDeleteContent","useState","previewOpen","setPreviewOpen","previewImage","setPreviewImage","previewTitle","setPreviewTitle","fileList","setFileList","useEffect","tempFileList","items","length","forEach","item","index","id","uid","toString","status","url","process","env","REACT_APP_BACKEND_URL","link","name","split","handleCancel","handlePreview","preview","originFileObj","substring","lastIndexOf","data","width"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/components/UploadFiles/index.tsx"],"sourcesContent":["import React from 'react';\nimport { Modal, Upload } from 'antd';\nimport type { RcFile } from 'antd/es/upload';\nimport type { UploadFile } from 'antd/es/upload/interface';\nimport {UploadFilesProps} from \"../../models/props/UploadFilesProps\";\nimport './UploadFiles.scss';\n\nconst getBase64 = (file: RcFile): Promise<string> =>\n    new Promise((resolve, reject) => {\n        const reader = new FileReader();\n        reader.readAsDataURL(file);\n        reader.onload = () => resolve(reader.result as string);\n        reader.onerror = (error) => reject(error);\n    });\n\nconst UploadFiles: React.FC<UploadFilesProps> = ({uploaded, callbackOnDeleteContent}) => {\n    const [previewOpen, setPreviewOpen] = React.useState<boolean>(false);\n    const [previewImage, setPreviewImage] = React.useState('');\n    const [previewTitle, setPreviewTitle] = React.useState('');\n    const [fileList, setFileList] = React.useState<UploadFile[]>([{} as UploadFile]);\n\n    React.useEffect(() => {\n        let tempFileList = [{} as UploadFile];\n        setFileList(tempFileList);\n\n        if (uploaded.items?.length > 0) {\n            uploaded.items.forEach((item, index) => {\n                if (item.id) {\n                    tempFileList[index] = {\n                        uid: item.id.toString(),\n                        status: \"done\",\n                        url: process.env.REACT_APP_BACKEND_URL + '/' + item.link,\n                        name: (process.env.REACT_APP_BACKEND_URL + '/' + item.link).split('/')[7]\n                    };\n                }\n            });\n            setFileList(tempFileList);\n        }\n    }, [uploaded]);\n\n    const handleCancel = () => setPreviewOpen(false);\n\n    const handlePreview = async (file: UploadFile) => {\n        if (!file.url && !file.preview) {\n            file.preview = await getBase64(file.originFileObj as RcFile);\n        }\n\n        setPreviewImage(file.url || (file.preview as string));\n        setPreviewOpen(true);\n        setPreviewTitle(file.name || file.url!.substring(file.url!.lastIndexOf('/') + 1));\n    };\n\n    /*const handleChange: UploadProps['onChange'] = ({ fileList: newFileList}) => {\n        setFileList(newFileList);\n    }*/\n\n    return (\n        <>\n            {fileList && (\n                <>\n                    <Upload\n                        action=\"https://www.mocky.io/v2/5cc8019d300000980a055e76\"\n                        listType=\"picture-card\"\n                        fileList={fileList}\n                        onPreview={handlePreview}\n                        onRemove={(data: UploadFile) => callbackOnDeleteContent(data.uid)}\n                    >\n                    </Upload>\n                    <Modal open={previewOpen} title={previewTitle} footer={null} onCancel={handleCancel}>\n                        <img alt=\"example\" style={{ width: '100%' }} src={previewImage} />\n                    </Modal>\n                </>\n            )\n            }\n        </>\n    );\n};\n\nexport default UploadFiles;"],"mappings":"0bAAA,MAAOA,MAAK,KAAM,OAAO,CACzB,OAASC,KAAK,CAAEC,MAAM,KAAQ,MAAM,CAIpC,MAAO,oBAAoB,CAAC,6IAE5B,GAAMC,UAAS,CAAG,QAAZA,UAAS,CAAIC,IAAY,QAC3B,IAAIC,QAAO,CAAC,SAACC,OAAO,CAAEC,MAAM,CAAK,CAC7B,GAAMC,OAAM,CAAG,GAAIC,WAAU,EAAE,CAC/BD,MAAM,CAACE,aAAa,CAACN,IAAI,CAAC,CAC1BI,MAAM,CAACG,MAAM,CAAG,iBAAML,QAAO,CAACE,MAAM,CAACI,MAAM,CAAW,GACtDJ,MAAM,CAACK,OAAO,CAAG,SAACC,KAAK,QAAKP,OAAM,CAACO,KAAK,CAAC,GAC7C,CAAC,CAAC,GAEN,GAAMC,YAAuC,CAAG,QAA1CA,YAAuC,MAA4C,IAAvCC,SAAQ,MAARA,QAAQ,CAAEC,uBAAuB,MAAvBA,uBAAuB,CAC/E,oBAAsCjB,KAAK,CAACkB,QAAQ,CAAU,KAAK,CAAC,oDAA7DC,WAAW,qBAAEC,cAAc,qBAClC,qBAAwCpB,KAAK,CAACkB,QAAQ,CAAC,EAAE,CAAC,qDAAnDG,YAAY,qBAAEC,eAAe,qBACpC,qBAAwCtB,KAAK,CAACkB,QAAQ,CAAC,EAAE,CAAC,qDAAnDK,YAAY,qBAAEC,eAAe,qBACpC,qBAAgCxB,KAAK,CAACkB,QAAQ,CAAe,CAAC,CAAC,CAAC,CAAe,CAAC,qDAAzEO,QAAQ,qBAAEC,WAAW,qBAE5B1B,KAAK,CAAC2B,SAAS,CAAC,UAAM,qBAClB,GAAIC,aAAY,CAAG,CAAC,CAAC,CAAC,CAAe,CACrCF,WAAW,CAACE,YAAY,CAAC,CAEzB,GAAI,kBAAAZ,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